#!/bin/bash

#------------------------------------------------------------------------------
#Filename:      PV.sh
#Version:       1.0
#Date:          2014/06/23
#Author:        xi.zhang
#Email:         xi.zhang@cs2c.com.cn
#Summary:       物理卷创建和删除、获取硬盘设备名称
#Notes:         实现物理卷的创建和删除/获取当前硬盘名称
#Copyright:     China Standard Software Co.,Ltd.
#History:
#               Version 1.0,2014/06/23
#               -The first one
#               Version 1.1,2014/11/13
#               -The second one
#               -Add "echo y" to pvcreate to avoid the interact with the terminal
#------------------------------------------------------------------------------

source ${SFROOT}/testcases/Management_Function/lib/Partition_parted.sh

##! @TODO: Create Physical Volume.
##! @AUTHOR: xi.zhang
##! @VERSION: 1.0 
##! @OUT: Create pv.txt include all Physical Volume Names.
function CreatePV()
{
    declare -a PVNAME
    for i in `seq 1 ${PVNUM}`
    do
        CreatePartition
        PARTITION=$?
        PVNAME[$i]="${HARD_DISK}${PARTITION}"
        echo y | pvcreate ${PVNAME[$i]}    
    done
    #echo ${PVNAME[*]} | tee pv.txt
    export PV=`echo ${PVNAME[@]}`
}

##! @TODO: Delete Physical Volumes.
##! @AUTHOR: xi.zhang
##! @VERSION: 1.0 
##! @OUT: Delete Physical Volumes.
function DeletePV()
{
    pvremove `pvs | awk '{print $1}' | tail -n ${PVNUM} | tr -t "\n" " "`  #only delete three new added PV
    for i in `seq 1 ${PVNUM}`
    do
        DeletePartition
    done
}
